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

🏷️ Fix generic type hinting of registry #3630

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Nov 23, 2023

A small improvement regarding type checking of the BaseRegistry class:

# Before
a = register("coSign")
reveal_type(a)  # Revealed type is "def (type[Any]) -> type[Any]"
b = a(...)
reveal_type(b)  # Revealed type is "Any"

# After
a = register("coSign")
reveal_type(a)  # Revealed type is "def a(type[BaseValidator]) -> type[BaseValidator]"
b = a(...)
reveal_type(b)  # Revealed type is "type[BaseValidator]"

I think it doesn't make sense to have a type alias to type[PluginType_co] outside any definition, because PluginType_co isn't bound to any generic class/function yet.

Only downside here is that in Callable[[type[PluginType_co]], type[PluginType_co]], type[PluginType_co] should also be a TypeVar bound to type[PluginType_co], but typevars bound to other typevars are not allowed.

Copy link

codecov bot commented Nov 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b237275) 95.96% compared to head (084ed69) 95.96%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3630      +/-   ##
==========================================
- Coverage   95.96%   95.96%   -0.01%     
==========================================
  Files         683      683              
  Lines       21912    21911       -1     
  Branches     2533     2533              
==========================================
- Hits        21028    21027       -1     
  Misses        611      611              
  Partials      273      273              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shame that it makes the type annotations considerably less readable, but if this is the only way to get it to work properly in editors then so be it

@sergei-maertens sergei-maertens merged commit 52c0e21 into master Nov 27, 2023
26 checks passed
@sergei-maertens sergei-maertens deleted the issue/registry-typing branch November 27, 2023 16:58
@Viicos
Copy link
Contributor Author

Viicos commented Nov 27, 2023

shame that it makes the type annotations considerably less readable, but if this is the only way to get it to work properly in editors then so be it

Yeah maybe that could be improved on the Python side

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.

2 participants