Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python 3.12+ and address pydantic v2 compatibility issues #41

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

eramongodb
Copy link
Contributor

This PR was prompted by the observation of the following error when running pytest with Python 3.12 on the shrub.py project:

AttributeError: 'EntryPoints' object has no attribute 'get'

As well as the following warning by pydantic in downstream projects with pydantic 2.0+:

UserWarning: Valid config keys have changed in V2:
* 'allow_population_by_field_name' has been renamed to 'populate_by_name'
  warnings.warn(message, UserWarning)

This prompted an investigation that uncovered a terrible mess of package compatibility issues and conflicting design philosophies across related packages which I will deliberately avoid summarizing here. Instead, I will simply reference the errors that were encountered and avoided by the proposed changes in this PR. These changes were tested against Python 3.8 through Python 3.13 using Astral uv.

Invoking flake8 via pytest-flake8

AttributeError: module 'flake8.options.config' has no attribute 'ConfigFileFinder'
AttributeError: 'Application' object has no attribute 'parse_preliminary_options_and_args'

Appears to be a conflict between flake8>=5.0 and pytest-flake8. Resolved by removing the pytest-flake8 package in favor of invoking flake8 directly in a new lint Evergreen task.

Note

Compatibility of Flake8 and pytest via pytest-flake8 seems unresolvable at the moment. This PR opts to workaround the problem by directly invoking flake8 instead.

Invoking flake8 with Python 3.12+

E231 missing whitespace after ':'

Appears to be a false positive with pycodestyle<2.11 (dependency of flake8==5.0). Resolved by upgrading flake8 to 7.0+.

pydantic 2.0 compatibility warning

UserWarning: Valid config keys have changed in V2:
  * 'allow_population_by_field_name' has been renamed to 'populate_by_name'

Resolved by renaming the field accordingly.

Important

This resolution is not backward-compatible with pydantic 1.0.

pydantic 2.0 deprecation warning

PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead.
PydanticDeprecatedSince20: The `json` method is deprecated; use `model_dump_json` instead.
PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead.

Resolved by using the recommended interfaces instead.

Important

This resolution is not backward-compatible with pydantic 1.0.

Python 3.14 deprecation warning

DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    assertmsg = ast.Str("")

Resolved by updating pytest to 7.0+.

pytest 7.0+ deprecation warning (black >= 24.0)

PytestDeprecationWarning: <class 'pytest_black.BlackItem'> is not using a cooperative constructor and only takes {'parent', 'fspath'}.
PytestRemovedIn8Warning: The (fspath: py.path.local) argument to BlackItem is deprecated. Please use the (path: pathlib.Path) argument instead.
PytestWarning: BlackItem is an Item subclass and should not be a collector, however its bases File are collectors.
  Please split the Collectors and the Item into separate node types.

Unresolved. Compatibility between black and pytest 7.0+ is not yet supported.

Note

These are the only warnings currently present when running pytest.

@eramongodb eramongodb requested a review from a team as a code owner October 30, 2024 16:43
@eramongodb eramongodb requested review from rongodb and aldo-aguilar and removed request for a team October 30, 2024 16:43
@gmishkin gmishkin requested review from namazgurbanovmdb and removed request for rongodb and aldo-aguilar October 30, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant