Skip to content

TypeError bug in rest_api when calculating complexity #166

@NejcS

Description

@NejcS

I was running the React task manager example and pointing codeplain to my local rest API. I had no other changes to that example. I got this error when rendering functionality 5.

TypeError: expected string or bytes-like object, got 'NoneType'

ERROR:__main__:Error handling user request. Exception expected string or bytes-like object, got 'NoneType'.
ERROR:__main__:Traceback (most recent call last):
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask_restx/api.py", line 404, in wrapper
    resp = resource(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask/views.py", line 109, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask_restx/resource.py", line 46, in dispatch_request
    resp = meth(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/app.py", line 496, in decorated
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/app.py", line 545, in decorated
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/app.py", line 509, in decorated
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/app.py", line 673, in post
    return codeplain_instance.render_functional_requirement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/codeplain.py", line 775, in render_functional_requirement
    code_complexity.check_implementation_complexity(patched_response_files, existing_files_content)
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/code_complexity.py", line 82, in check_implementation_complexity
    [changed_files, changed_files_count, changed_lines_count, excluded_files] = calculate_implementation_complexity(
                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/code_complexity.py", line 73, in calculate_implementation_complexity
    changed_file_lines_count = calculate_complexity_score(file_name, original_file, response_file)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/code_complexity.py", line 47, in calculate_complexity_score
    response_file = strip_tsx(response_file)
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/code_complexity.py", line 34, in strip_tsx
    src = re.sub(r"\sstyle\s*=\s*\{[^}]*\}", "", src)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/.local/share/uv/python/cpython-3.11.15-macos-aarch64-none/lib/python3.11/re/__init__.py", line 185, in sub
    return _compile(pattern, flags).sub(repl, string, count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

ERROR:app:Exception on /render_functional_requirement [POST]
Traceback (most recent call last):
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask_restx/api.py", line 404, in wrapper
    resp = resource(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask/views.py", line 109, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/.venv/lib/python3.11/site-packages/flask_restx/resource.py", line 46, in dispatch_request
    resp = meth(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/app.py", line 496, in decorated
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/app.py", line 545, in decorated
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/app.py", line 509, in decorated
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/app.py", line 673, in post
    return codeplain_instance.render_functional_requirement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/codeplain.py", line 775, in render_functional_requirement
    code_complexity.check_implementation_complexity(patched_response_files, existing_files_content)
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/code_complexity.py", line 82, in check_implementation_complexity
    [changed_files, changed_files_count, changed_lines_count, excluded_files] = calculate_implementation_complexity(
                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/code_complexity.py", line 73, in calculate_implementation_complexity
    changed_file_lines_count = calculate_complexity_score(file_name, original_file, response_file)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/code_complexity.py", line 47, in calculate_complexity_score
    response_file = strip_tsx(response_file)
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/codeplain/plain2code_rest_api/src/code_complexity.py", line 34, in strip_tsx
    src = re.sub(r"\sstyle\s*=\s*\{[^}]*\}", "", src)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nejcstebe/.local/share/uv/python/cpython-3.11.15-macos-aarch64-none/lib/python3.11/re/__init__.py", line 185, in sub
    return _compile(pattern, flags).sub(repl, string, count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
INFO:werkzeug:127.0.0.1 - - [21/Apr/2026 08:31:15] "POST /render_functional_requirement HTTP/1.1" 500 -

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions