Type hints and Response.selector
See original GitHub issuePython 3.5 introduced Type Hints: https://docs.python.org/3/library/typing.html
I’m using them with Scrapy’s response object, but it seems that however you’ve declared selectors in scrapy it makes PyCharm unable to realise there’s a selector method/attribute:
from scrapy.http import Response
def my_function(response: Response):
response.selector.remove_namespaces()
For which PyCharm reports: “Unresolved attribute reference ‘selector’ for class ‘Response’” Obviously the selector works, but it’s not being exposed sufficiently well for the IDE to be able to spot it which obviates the point of type hints.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
typing — Support for type hints — Python 3.11.1 documentation
This module provides runtime support for type hints. The most fundamental support consists of the types Any , Union , Callable , TypeVar...
Read more >Advanced static type hints in Python | Lab Digital
A writeup of advanced python static type annotation techniques (protocols, aliasing, generics) and its implications (automated property ...
Read more >Putting Type Hints to Work - YouTube
Python 3.5 and Python 3.6 embraced optional typing as part of the Python language. WAT? TYPING IN PYTHON?This webinar introduces the subject ...
Read more >Python Types Intro - FastAPI
These "type hints" are a special syntax that allow declaring the type of a variable. By declaring types for your variables, editors and...
Read more >Type hints cheat sheet - mypy 0.991 documentation
Technically many of the type annotations shown below are redundant, since mypy can usually infer the type of a variable from its value....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
probably you need
or just
Type hints are correct in pointing this out - Response doesn’t have .selector attribute, only TextResponse does. Scrapy selects Response subclass based on server response body and headers; for binary data it’d be just Response (=> no parsed HTML tree), while for HTML it’d be HtmlResponse, which is a Response subclass.