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

Update pyi #181

Merged
merged 8 commits into from
Oct 26, 2021
Merged

Update pyi #181

merged 8 commits into from
Oct 26, 2021

Conversation

BTWS2
Copy link
Collaborator

@BTWS2 BTWS2 commented Oct 23, 2021

There is an undocumented way to check if the stubs are up to date, but I can't get it to work, so I compared it manually. I get:

py -3.9 -m mypy.stubtest checks.py

Nothing to do?!
error: checks.py failed to find stubs
Stub:
MISSING
Runtime:
None

https://stackoverflow.com/questions/51716200/how-do-you-check-if-a-typeshed-stub-pyi-file-matches-the-implementation
python/mypy#5028 (comment)

@BTWS2 BTWS2 added the documentation Improvements or additions to documentation label Oct 23, 2021
@BTWS2 BTWS2 requested a review from stijndcl October 23, 2021 16:48
validators/checks.pyi Outdated Show resolved Hide resolved
@stijndcl
Copy link
Collaborator

stijndcl commented Oct 23, 2021

but I can't get it to work

The StackOverflow article you linked suggests you're doing it wrong:

Running stubtest yeilds no output, and a zero exit code:

$ python -m mypy.stubtest simple

$ echo $?
0

Notice how there's no file extension there, it's only the name of the module (simple instead of simple.py). Then, if you run it from the /validators directory it will fail because your base path is now ./validators instead of ./ so none of the imports are valid anymore.

The correct way to run it is to go to the root of the repo, and use python3 -m mypy.stubtest validators.checks - notice validators.checks instead of validators/checks because that's the way python module paths work. validators/checks would fail too.

The output I get for this is:

Click to expand
stijn@jarvis $ python3 -m mypy.stubtest validators.checks      
                     
error: not checking stubs due to mypy build errors:
utils/color_converter.py:410: error: Syntax error in type annotation
utils/color_converter.py:410: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
utils/color_converter.py:422: error: Argument 1 to "rgb_to_name" has incompatible type "Optional[str]"; expected "str"
utils/color_converter.py:423: error: Argument 1 to "name_to_rgba" has incompatible type "Optional[str]"; expected "str"
utils/color_converter.py:427: error: Argument 1 to "name_to_hex" has incompatible type "Optional[str]"; expected "str"
utils/color_converter.py:429: error: Argument 1 to "name_to_rgba" has incompatible type "Optional[str]"; expected "str"
utils/color_converter.py:441: error: Argument 1 to "name_to_hex" has incompatible type "Optional[str]"; expected "str"
utils/color_converter.py:442: error: Argument 1 to "name_to_rgb" has incompatible type "Optional[str]"; expected "str"
validators/css_validator.pyi:3: error: Skipping analyzing "bs4.element": found module but no type hints or library stubs
validators/css_validator.pyi:4: error: Skipping analyzing "lxml.etree": found module but no type hints or library stubs
validators/css_validator.pyi:5: error: Skipping analyzing "tinycss2.ast": found module but no type hints or library stubs
validators/css_validator.pyi:10: error: Bracketed expression "[...]" is not valid as a type
validators/css_validator.pyi:10: note: Did you mean "List[...]"?
validators/css_validator.pyi:21: error: Bracketed expression "[...]" is not valid as a type
validators/css_validator.pyi:21: note: Did you mean "List[...]"?
validators/css_validator.pyi:25: error: Bracketed expression "[...]" is not valid as a type
validators/css_validator.pyi:25: note: Did you mean "List[...]"?
validators/css_validator.pyi:27: error: Syntax error in type annotation
validators/css_validator.pyi:27: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
validators/css_validator.pyi:31: error: Bracketed expression "[...]" is not valid as a type
validators/css_validator.pyi:31: note: Did you mean "List[...]"?
validators/css_validator.pyi:41: error: Syntax error in type annotation
validators/css_validator.pyi:41: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
validators/css_validator.pyi:45: error: Bracketed expression "[...]" is not valid as a type
validators/css_validator.pyi:45: note: Did you mean "List[...]"?
validators/css_validator.pyi:46: error: Invalid type comment or annotation
validators/css_validator.pyi:66: error: Invalid type comment or annotation
exceptions/html_exceptions.pyi:27: error: Bracketed expression "[...]" is not valid as a type
exceptions/html_exceptions.pyi:27: note: Did you mean "List[...]"?
exceptions/html_exceptions.pyi:27: error: Syntax error in type annotation
exceptions/html_exceptions.pyi:27: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
exceptions/html_exceptions.pyi:75: error: Bracketed expression "[...]" is not valid as a type
exceptions/html_exceptions.pyi:75: note: Did you mean "List[...]"?
exceptions/html_exceptions.pyi:75: error: Syntax error in type annotation
exceptions/html_exceptions.pyi:75: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
exceptions/html_exceptions.pyi:86: error: Incompatible types in assignment (expression has type "List[LocatableHtmlValidationError]", base class "DelayedExceptions" defined the type as "List[Exception]")
exceptions/html_exceptions.pyi:86: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
exceptions/html_exceptions.pyi:86: note: Consider using "Sequence" instead, which is covariant
validators/double_chars_validator.pyi:56: error: Syntax error in type annotation
validators/double_chars_validator.pyi:56: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
validators/double_chars_validator.pyi:66: error: Bracketed expression "[...]" is not valid as a type
validators/double_chars_validator.pyi:66: note: Did you mean "List[...]"?
validators/html_validator.pyi:29: error: Argument 1 of "error" is incompatible with supertype "ParserBase"; supertype defines the argument type as "str"
validators/html_validator.pyi:29: note: This violates the Liskov substitution principle
validators/html_validator.pyi:29: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
validators/html_validator.pyi:41: error: Argument 2 of "handle_starttag" is incompatible with supertype "HTMLParser"; supertype defines the argument type as "List[Tuple[str, Optional[str]]]"
validators/html_validator.pyi:41: note: This violates the Liskov substitution principle
validators/html_validator.pyi:41: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
validators/checks.pyi:3: error: Skipping analyzing "bs4": found module but no type hints or library stubs
validators/checks.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
validators/checks.pyi:4: error: Skipping analyzing "bs4.element": found module but no type hints or library stubs

Some of these we can't do anything about (untyped libraries), some we can and might in the future.

Copy link
Collaborator

@stijndcl stijndcl left a comment

Choose a reason for hiding this comment

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

We use typing.X types across the judge to make it compatible with Python 3.8. All lowercase typehints (list[...], tuple[...], dict[...], ...) are 3.9 features and are invalid syntax in 3.8. I've modified the workflow to run tests on both 3.8 and 3.9.

@BTWS2 BTWS2 requested a review from stijndcl October 25, 2021 10:56
@stijndcl stijndcl merged commit 2ba98f7 into main Oct 26, 2021
@stijndcl stijndcl deleted the check_pyi branch October 26, 2021 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants