AttributeError: 'int' object has no attribute 'isdigit'
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 102
- Forks
- 78
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
User receives AttributeError: 'int' object has no attribute 'isdigit' when manually entering array_sizes for parameters.
To Reproduce
Steps to reproduce the behavior:
- undef OS_MAX_PATH_LEN
- Edit
CHeaderParser-hdr-paths.txtand remove#onfm_msgdefs.handfm_msg.h - Run
python3 CHeaderParser.py - Enter the file name to save, I chose fm_app_cmd_file
- Type
yes - Pick a command with parameters which contains usage of
OS_MAX_PATH_LENe.g. I am choosingFM_DECOMPRESS - Choose the appropriate struct e.g.
10 - Choose the line containing OS_MAX_PATH_LEN e.g.
2 - Enter any value for OS_MAX_PATH_LEN
- See error below
Expected behavior
Traceback (most recent call last):
File "CHeaderParser.py", line 451, in <module>
while not array_size.isdigit() or int(
AttributeError: 'int' object has no attribute 'isdigit'
Code snips
https://github.com/nasa/cFS-GroundSystem/blob/main/Subsystems/cmdGui/CHeaderParser.py#L450-L467
while not array_size.isdigit() or int(
array_size) not in range(129):
# User input is not an integer
if not array_size.isdigit():
print("Could not translate",
array_name_size[1])
else:
print(
"Array size out of bounds. It must be between 0 and 128."
)
try:
# Try to translate user input to an integer
array_size = int(
input(
(f"Please enter the defined value for "
f"{array_name_size[1]} (0 - 128): ")))
except ValueError:
pass # Ignore non-integer and try again
System observed on:
- Hardware: VirtualBox
- OS: Ubuntu 20.04
- Versions [e.g. cFE 6.6, OSAL 4.2, PSP 1.3 for mcp750, any related apps]
Fix
I believe the fix to be to remove int on the input function on line 462 : https://github.com/nasa/cFS-GroundSystem/blob/main/Subsystems/cmdGui/CHeaderParser.py#L462 like so:
while not array_size.isdigit() or int(
array_size) not in range(129):
# User input is not an integer
if not array_size.isdigit():
print("Could not translate",
array_name_size[1])
else:
print(
"Array size out of bounds. It must be between 0 and 128."
)
try:
# Try to translate user input to an integer
array_size = input(
(f"Please enter the defined value for "
f"{array_name_size[1]} (0 - 128): "))
except ValueError:
pass # Ignore non-integer and try again
Additional context
If you want to maintain the array_size as type int you can set the array_size to int array_size = int(array_size) after that while block above.
Reporter Info
Charles Taylor ER6
Johnson Space Center
I am on Teams
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Subsystems/cmdGui/CHeaderParser.py around lines 450-467 and reproduce the manual array_sizes flow with python3 CHeaderParser.py. Check the type used by array_size during validation and confirm that valid values from 0 through 128 are accepted without the AttributeError, while invalid values continue prompting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100