Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Type stubs (mypy) support? #1160

Answered by mdmintz
feslima asked this question in Q&A
Discussion options

First of all, amazing work!

Any plans to incorporate static typing support with mypy?

You must be logged in to vote

Hello @feslima! Thank you, and welcome to SeleniumBase discussions!
SeleniumBase has its own system of type verification, such as demonstrated in the below code snippet, which processes all inputs of selectors for SeleniumBase methods:

...
_type = type(selector) # First make sure the selector is a string
not_string = False
if not python3:
 if _type is not str and _type is not unicode: # noqa: F821
 not_string = True
else:
 if _type is not str:
 not_string = True
if not_string:
 msg = "Expecting a selector of type: \"<class 'str'>\" (string)!"
 raise Exception('Invalid selector type: "%s"\n%s' % (_type, msg))
...

With all these in place, it's not necessary to ad...

Replies: 1 comment 2 replies

Comment options

Hello @feslima! Thank you, and welcome to SeleniumBase discussions!
SeleniumBase has its own system of type verification, such as demonstrated in the below code snippet, which processes all inputs of selectors for SeleniumBase methods:

...
_type = type(selector) # First make sure the selector is a string
not_string = False
if not python3:
 if _type is not str and _type is not unicode: # noqa: F821
 not_string = True
else:
 if _type is not str:
 not_string = True
if not_string:
 msg = "Expecting a selector of type: \"<class 'str'>\" (string)!"
 raise Exception('Invalid selector type: "%s"\n%s' % (_type, msg))
...

With all these in place, it's not necessary to add in additional type handling. And it wouldn't be possible either because SeleniumBase supports Python versions 2.7, 3.5, 3.6, 3.7, 3.8, 3.9, and 3.10 (whereas mypy doesn't support the earliest versions listed there).
However, if people desire to add in support to their own programs that use SeleniumBase (and they have a newer version of Python), then they are welcome to add in typing support to their own code.

You must be logged in to vote
2 replies
Comment options

Thanks for enlightenment @mdmintz.

One more question: Is it possible to set these configurations via a pyproject.toml file like mypy does? Or even a specific config file (e.g. .ini, .yaml, etc.) for SeleniumBase? I couldn't find anything mentioned in the docs.

Thanks again for the attention.

Comment options

Hi @feslima, yes, you can use a pytest.ini file for that, eg: https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini

I talk about it in the main ReadMe.md file:

🔵 When running tests with pytest, you'll want a copy of pytest.ini in your root folders. When running tests with nosetests, you'll want a copy of setup.cfg in your root folders. These files specify default configuration details for tests. Folders should also include a blank __init__.py file, which allows your tests to import files from that folder.

Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /