Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Update mypy to 0.930 #508

Merged
merged 5 commits into from
Dec 27, 2021
Merged

Update mypy to 0.930 #508

merged 5 commits into from
Dec 27, 2021

Conversation

achimnol
Copy link
Member

This PR fixes new typecheck errors found by mypy 0.930 update.

We just fallback to `typing.Any` and make an explicit type-cast, instead of
resolving the generic type argument at runtime to automatically get
the reference to `uuid_subtype_func`.

Here is the story:

Currently Python does not allow introspection of generic type arguments
in runtime.  For some limited cases, we could refer `__orig_bases__`, but
somehow it does not work for us and it is a known limitation that we
cann t resolve it early in the object lifecycle.
(ref: https://stackoverflow.com/questions/57706180, python/typing#658)

Moreover, SQLAlchemy's `TypeDecorator` also involves its own metaclass logic
from `TraversibleType`, which makes `__orig_class__` unavailable.
@achimnol achimnol added this to the 21.03 milestone Dec 27, 2021
@achimnol achimnol self-assigned this Dec 27, 2021
@codecov
Copy link

codecov bot commented Dec 27, 2021

Codecov Report

Merging #508 (ac20a92) into main (a508ebc) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #508      +/-   ##
==========================================
+ Coverage   48.83%   48.87%   +0.03%     
==========================================
  Files          54       54              
  Lines        8951     8952       +1     
==========================================
+ Hits         4371     4375       +4     
+ Misses       4580     4577       -3     
Impacted Files Coverage Δ
src/ai/backend/manager/defs.py 100.00% <100.00%> (ø)
src/ai/backend/manager/distributed.py 93.10% <100.00%> (+0.24%) ⬆️
src/ai/backend/manager/models/base.py 52.47% <100.00%> (+0.82%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a508ebc...ac20a92. Read the comment docs.

@achimnol achimnol merged commit cf1ef92 into main Dec 27, 2021
@achimnol achimnol deleted the fix/update-mypy-0.930 branch December 27, 2021 16:07
achimnol added a commit that referenced this pull request Dec 27, 2021
* setup: Set the minimum mypy version to 0.930
* fix: New typecheck errors due to stricter enum validation
* fix: Workaround limitation of type variable usage in ClassVar

  We just fallback to `typing.Any` and make an explicit type-cast, instead of
  resolving the generic type argument at runtime to automatically get
  the reference to `uuid_subtype_func`.

  Here is the story:

  Currently Python does not allow introspection of generic type arguments
  in runtime.  For some limited cases, we could refer `__orig_bases__`, but
  somehow it does not work for us and it is a known limitation that we
  cann t resolve it early in the object lifecycle.
  (ref: https://stackoverflow.com/questions/57706180, python/typing#658)

  Moreover, SQLAlchemy's `TypeDecorator` also involves its own metaclass logic
  from `TraversibleType`, which makes `__orig_class__` unavailable.

Backported-From: main (22.03)
Backported-To: 21.09
achimnol added a commit that referenced this pull request Dec 27, 2021
* setup: Set the minimum mypy version to 0.930
* fix: New typecheck errors due to stricter enum validation
* fix: Workaround limitation of type variable usage in ClassVar

  We just fallback to `typing.Any` and make an explicit type-cast, instead of
  resolving the generic type argument at runtime to automatically get
  the reference to `uuid_subtype_func`.

  Here is the story:

  Currently Python does not allow introspection of generic type arguments
  in runtime.  For some limited cases, we could refer `__orig_bases__`, but
  somehow it does not work for us and it is a known limitation that we
  cann t resolve it early in the object lifecycle.
  (ref: https://stackoverflow.com/questions/57706180, python/typing#658)

  Moreover, SQLAlchemy's `TypeDecorator` also involves its own metaclass logic
  from `TraversibleType`, which makes `__orig_class__` unavailable.

Backported-From: main (22.03)
Backported-To: 21.03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant