Add new attributes for rendering?
Your question is exactly about this issue:


  Allow instantiating Attribute objects within Twig
  
  Problem/Motivation
  
  Sometimes you have an array of attributes and it would be nice if you
  could addClass, removeClass, setAttribute, etc. rather than trying to
  do array manipulation.
  
  Proposed resolution
  
  Add a function to our Twig extension to allow creating an Attribute
  object from an array of attributes.


Issue: https://www.drupal.org/node/2616756

And the change record for 8.3.x:

{% set my_attribute = create_attribute() %}
{%
  set my_classes = [
    'kittens',
    'llamas',
    'puppies',
  ]
%}
&lt;div{{ my_attribute.addClass(my_classes).addAttribute('id', 'myUniqueId') }}&gt;
  {{ content }}
&lt;/div&gt;
&lt;div{{ create_attribute({'class': ['region', 'region--header']}) }}&gt;
  {{ content }}
&lt;/div&gt;


https://www.drupal.org/node/2818293