I am adding type hints to my code base.[...]
In the other module I have this -
def config_database(db_params):
To add a type hint, I now have this -
def config_database(db_params: configparser.SectionProxy):
To get this to work, I have to add 'import configparser' at the top of
the module.
I have three separate modules, one for each database, with a subclass >containing the methods and attributes specific to that database. Each
one has a connect() method which receives db_params as a parameter.
Now I have to add 'import configparser' at the top of each of these
modules in order to type hint the method.
This seems verbose. If it is the correct way of doing it I can live
with it, but I wondered if there was an easier way.
I have to add 'import configparser' at the top of each of these modules
in order to type hint the method.
This seems verbose. If it is the correct way of doing it I can live with
it, but I wondered if there was an easier way.
On 12/13/23 00:19, Frank Millman via Python-list wrote:
I have to add 'import configparser' at the top of each of these
modules in order to type hint the method.
This seems verbose. If it is the correct way of doing it I can live
with it, but I wondered if there was an easier way.
Think of import as meaning "make this available in my current (module) namespace".
The actual import machinery only runs the first time, that is, if it's
not already present in the sys.modules dict.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 447 |
Nodes: | 16 (2 / 14) |
Uptime: | 24:36:01 |
Calls: | 9,235 |
Calls today: | 2 |
Files: | 13,496 |
Messages: | 6,063,718 |