fqdn icon indicating copy to clipboard operation
fqdn copied to clipboard

Empty string should not raise ValueError on construction

Open shane-kearns opened this issue 11 months ago • 0 comments

A ValueError is raised here if passing the empty string '' since it is a false value. https://github.com/ypcrts/fqdn/blob/84290063933d4a17620e07dc6db8d8965d89d8c2/fqdn/init.py#L43

The correct line should read:

        if not isinstance(fqdn, str):
            raise ValueError("fqdn must be str")

Since isinstance(None, str) is valid python and returns False.

Which gives the following behaviour that I think is correct:

Python 3.12.2 (tags/v3.12.2:6abddd9, Feb  6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from fqdn import FQDN
>>> a = FQDN('')
>>> a.is_valid
False
>>> b = FQDN()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: FQDN.__init__() missing 1 required positional argument: 'fqdn'
>>> c = FQDN(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\shane.kearns\Documents\git\prappspec\tests\.virtualenv\Lib\site-packages\fqdn\__init__.py", line 44, in __init__
    raise ValueError("fqdn must be str")
ValueError: fqdn must be str

shane-kearns avatar Mar 04 '24 15:03 shane-kearns