Skip to content

Writing all function signatures in Python#631

Merged
jcfreeman2 merged 4 commits into
developfrom
PawelPlesniak/Mypy
Jul 23, 2026
Merged

Writing all function signatures in Python#631
jcfreeman2 merged 4 commits into
developfrom
PawelPlesniak/Mypy

Conversation

@PawelPlesniak

@PawelPlesniak PawelPlesniak commented Jul 20, 2026

Copy link
Copy Markdown

Description

Prepares the repository for static type checking with mypy. The py.typed file is required to indicate that the code is ready for type checking, as per the PEP561 standards.

Type of change

  • Documentation (non-breaking change that adds or improves the documentation)
  • New feature or enhancement (non-breaking change which adds functionality)
  • Optimization (non-breaking change that improves code/performance)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Testing checklist

  • Unit tests pass (e.g. dbt-build --unittest)
  • Minimal system quicktest passes (pytest -s minimal_system_quick_test.py)
  • Full set of integration tests pass (dunedaq_integtest_bundle.sh)
  • Python tests pass if applicable (e.g. python -m pytest)
  • Pre-commit hooks run successfully if applicable (e.g. pre-commit run --all-files)

Comments here on the testing

Further checks

  • Code is commented where needed, particularly in hard-to-understand areas
  • Code style is correct (dbt-build --lint, and/or see https://dune-daq-sw.readthedocs.io/en/latest/packages/styleguide/)
  • If applicable, new tests have been added or an issue has been opened to tackle that in the future.
    (Indicate issue here: # (issue))

@PawelPlesniak PawelPlesniak mentioned this pull request Jul 21, 2026
25 tasks
@PawelPlesniak

Copy link
Copy Markdown
Author

Note, dbt-build --lint, has uncovered several issues that have not been addressed, as these are not associated with changes made to this repository.

@PawelPlesniak

Copy link
Copy Markdown
Author

The dbt-build --lint logs are included here for reference

=========================Checking sourcecode/daqconf/apps/create_config_plot.cxx=========================
Done processing sourcecode/daqconf/apps/create_config_plot.cxx
Total errors found: 0

Applying duneclang-tidy.sh to sourcecode/daqconf/apps/create_config_plot.cxx
/nfs/home/pplesnia/nightlyDev/260720/styleguide/cpplint/duneclang-tidy.sh build sourcecode/daqconf/apps/create_config_plot.cxx

=========================Checking sourcecode/daqconf/apps/create_config_plot.cxx=========================

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:27:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
   27 | namespace dunedaq {
      | 
~~~~~~~~~~~~~~~~~~
   28 | namespace conffwk {
      | ~~~~~~~~~~~~~~~~~
      | namespace dunedaq::conffwk
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:248:5: warning: return type 'const std::string' (aka 'const basic_string<char>') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]
  248 |     const std::string full_name() const noexcept { return UID() + '@' + class_name(); }
      |     
~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:256:5: warning: return type 'const std::string' (aka 'const basic_string<char>') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]
  256 |     const std::string contained_in() const
      |     
~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:337:10: warning: consider replacing 'unsigned long' with 'uint64' [google-runtime-int]
  337 |                        unsigned long rlevel = 0,
      |                        

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:630:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  630 |   private:
      |   
~~~~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:618:3: note: previously declared here
  618 |   private:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:25:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
   25 | namespace dunedaq {
      | 
~~~~~~~~~~~~~~~~~~
   26 | namespace conffwk {
      | ~~~~~~~~~~~~~~~~~
      | namespace dunedaq::conffwk
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:86:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
   86 |   public:
      |   
~~~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:80:3: note: previously declared here
   80 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:104:5: warning: return type 'const std::string' (aka 'const basic_string<char>') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]
  104 |     virtual const std::string contained_in() const = 0;
      |     
       ~~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:106:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  106 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:148:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  148 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:190:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  190 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:196:125: warning: consider replacing 'unsigned long' with 'uint64' [google-runtime-int]
  196 |     virtual void referenced_by(std::vector<ConfigObject>& value, const std::string& association, bool check_composite_only, unsigned long rlevel, const std::vector<std::string> * rclasses) const = 0;
      |                                                                                                                             

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:199:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  199 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:250:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  250 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:324:11: warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast]
  324 |           const_cast<ConfigObjectImpl *>(this)->reset();
      |           

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:340:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  340 |   protected:
      |   
~~~~~~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:331:3: note: previously declared here
  331 |   protected:
      |   

Applying dunecpplint.sh to sourcecode/daqconf/apps/GraphBuilder.cpp

=========================Checking sourcecode/daqconf/apps/GraphBuilder.cpp=========================
sourcecode/daqconf/apps/GraphBuilder.cpp:383:  Small and focused functions are preferred: GraphBuilder::calculate_network_connections() has 100 non-comment lines (error triggered by exceeding 80 lines) (disable this by putting "// NOLINT" after the function's closing brace.)  [readability/fn_size] [1]
sourcecode/daqconf/apps/GraphBuilder.cpp:511:  Small and focused functions are preferred: GraphBuilder::find_objects_and_connections() has 84 non-comment lines (error triggered by exceeding 80 lines) (disable this by putting "// NOLINT" after the function's closing brace.)  [readability/fn_size] [1]
sourcecode/daqconf/apps/GraphBuilder.cpp:827:  Small and focused functions are preferred: GraphBuilder::write_graph() has 142 non-comment lines (error triggered by exceeding 80 lines) (disable this by putting "// NOLINT" after the function's closing brace.)  [readability/fn_size] [1]
Done processing sourcecode/daqconf/apps/GraphBuilder.cpp
Total errors found: 6
sourcecode/daqconf/apps/GraphBuilder.cpp:853:  Namespace should be terminated with '// namespace daqconf  '  [readability/namespace] [5]
sourcecode/daqconf/apps/GraphBuilder.cpp:426:  Add #include <memory> for make_shared<>  [build/include_what_you_use] [4]
sourcecode/daqconf/apps/GraphBuilder.cpp:799:  Add #include <utility> for pair<>  [build/include_what_you_use] [4]

Applying duneclang-tidy.sh to sourcecode/daqconf/apps/GraphBuilder.cpp
/nfs/home/pplesnia/nightlyDev/260720/styleguide/cpplint/duneclang-tidy.sh build sourcecode/daqconf/apps/GraphBuilder.cpp

=========================Checking sourcecode/daqconf/apps/GraphBuilder.cpp=========================

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:27:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
   27 | namespace dunedaq {
      | 
~~~~~~~~~~~~~~~~~~
   28 | namespace conffwk {
      | ~~~~~~~~~~~~~~~~~
      | namespace dunedaq::conffwk
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:248:5: warning: return type 'const std::string' (aka 'const basic_string<char>') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]
  248 |     const std::string full_name() const noexcept { return UID() + '@' + class_name(); }
      |     
~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:256:5: warning: return type 'const std::string' (aka 'const basic_string<char>') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]
  256 |     const std::string contained_in() const
      |     
~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:337:10: warning: consider replacing 'unsigned long' with 'uint64' [google-runtime-int]
  337 |                        unsigned long rlevel = 0,
      |                        

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:630:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  630 |   private:
      |   
~~~~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObject.hpp:618:3: note: previously declared here
  618 |   private:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:25:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
   25 | namespace dunedaq {
      | 
~~~~~~~~~~~~~~~~~~
   26 | namespace conffwk {
      | ~~~~~~~~~~~~~~~~~
      | namespace dunedaq::conffwk
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:86:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
   86 |   public:
      |   
~~~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:80:3: note: previously declared here
   80 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:104:5: warning: return type 'const std::string' (aka 'const basic_string<char>') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]
  104 |     virtual const std::string contained_in() const = 0;
      |     
       ~~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:106:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  106 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:148:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  148 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:190:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  190 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:196:125: warning: consider replacing 'unsigned long' with 'uint64' [google-runtime-int]
  196 |     virtual void referenced_by(std::vector<ConfigObject>& value, const std::string& association, bool check_composite_only, unsigned long rlevel, const std::vector<std::string> * rclasses) const = 0;
      |                                                                                                                             

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:199:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  199 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:250:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  250 |   public:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:324:11: warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast]
  324 |           const_cast<ConfigObjectImpl *>(this)->reset();
      |           

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:340:3: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]
  340 |   protected:
      |   
~~~~~~~~~
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/ConfigObjectImpl.hpp:331:3: note: previously declared here
  331 |   protected:
      |   

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/conffwk/include/conffwk/Schema.hpp:22:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
   22 | namespace dunedaq {
      | 
~~~~~~~~~~~~~~~~~~
   23 |   namespace conffwk {
      |   ~~~~~~~~~~~~~~~~~
      |   namespace dunedaq::conffwk
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/daqconf/apps/GraphBuilder.cpp:72:11: warning: thrown exception type is not nothrow copy constructible [cert-err60-cpp]
   72 |     throw exc;
      |           

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/daqconf/apps/GraphBuilder.cpp:328:23: warning: local copy 'incoming_vertex_name' of the variable 'incoming_conn' is never modified; consider avoiding the copy [performance-unnecessary-copy-initialization]
  328 |     const std::string incoming_vertex_name = incoming_conn;
      |                       

      |                      &
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/daqconf/apps/GraphBuilder.cpp:359:23: warning: local copy 'outgoing_vertex_name' of the variable 'outgoing_conn' is never modified; consider avoiding the copy [performance-unnecessary-copy-initialization]
  359 |     const std::string outgoing_vertex_name = outgoing_conn;
      |                       

      |                      &
/nfs/home/pplesnia/nightlyDev/260720/sourcecode/daqconf/apps/GraphBuilder.cpp:418:13: warning: thrown exception type is not nothrow copy constructible [cert-err60-cpp]
  418 |       throw exc;
      |             

/nfs/home/pplesnia/nightlyDev/260720/sourcecode/daqconf/apps/GraphBuilder.cpp:584:10: warning: expression result unused [clang-diagnostic-unused-value]
  580 |       boost::add_edge(possible_sender_object.vertex_in_graph,
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  581 |                       m_objects_for_graph.at(receiver_info.receiver_label).vertex_in_graph,
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  582 |                       { receiver_info.connection_name },
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  583 |                       m_graph)
      |                       ~~~~~~~~
  584 |         .first;
      |          

Applying dunecpplint.sh to sourcecode/daqconf/apps/GraphBuilder.hpp

=========================Checking sourcecode/daqconf/apps/GraphBuilder.hpp=========================
Done processing sourcecode/daqconf/apps/GraphBuilder.hpp
Total errors found: 0

Applying dunecpplint.sh to sourcecode/daqconf/unittest/Graph_test.cxx

=========================Checking sourcecode/daqconf/unittest/Graph_test.cxx=========================
Done processing sourcecode/daqconf/unittest/Graph_test.cxx
Total errors found: 1
sourcecode/daqconf/unittest/Graph_test.cxx:1:  C-style comment syntax detected; please use either C++ style "//" or Doxygen style  [readability/comment] [3]

Applying duneclang-tidy.sh to sourcecode/daqconf/unittest/Graph_test.cxx
/nfs/home/pplesnia/nightlyDev/260720/styleguide/cpplint/duneclang-tidy.sh build sourcecode/daqconf/unittest/Graph_test.cxx

=========================Checking sourcecode/daqconf/unittest/Graph_test.cxx=========================

@jcfreeman2 jcfreeman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This successfully builds as part of a test build from this morning, MYPYFD_DEV_260723_A9, and integration tests all pass (i.e., this doesn't break anything). Note that building it won't generate *.pyi files automatically since right now *.pyi file generation is only done as part of calls to daq_add_python_bindings - this will require some thought on the part of Software Coordination as to what to do about daq-cmake in this regard.

However, if I run pybind11-stubgen daqconf from the command line, I do see stubs/daqconf/__init__.pyi created, which I believe is what was intended.

@jcfreeman2
jcfreeman2 merged commit c1c889c into develop Jul 23, 2026
5 checks passed
@jcfreeman2
jcfreeman2 deleted the PawelPlesniak/Mypy branch July 23, 2026 17:45
@PawelPlesniak

Copy link
Copy Markdown
Author

Thank you for reviewing @jcfreeman2
Note, for signature checking, it is not necessary to have separate stub files (*.pyi). The type checker (in our case, this is mypy) can be run its checks on the source code if the source code has the relevant types hinted (function signatures and return types specified), which is what this PR changed.

Stub files are required when the source python code does not include type hinting, which is the case when we check against python code generated from pybind11, as this generates .so files which are used through macros instead of .py files. As an example from today's nightly, the pybind11-defined python code is in

/cvmfs/dunedaq-development.opensciencegrid.org/nightly/NB_DEV_260724_A9/spack-0.22.0/opt/spack/linux-almalinux9-x86_64/gcc-14.3.0/conffwk-NB_DEV_260724_A9-e567dohaegaj552gxzmsium6qypki7cn/lib64/python/conffwk/_daq_conffwk_py.so

The use of the static type checking on this code will require stub files, as the .so file does not contain the relevant information needed for the type checking.

TLDR - if native python code is written with type hinting, no stub files will be required. Generally, python code generated through pybind11 will require stub files for static type checking. As this repo does not have pybindsrc, I would not expect these files to be generated regardless.

I am following DUNE-DAQ/daq-cmake#174 to see when I can merge in some of our mypy work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants